From 7f4d7aa04b125939032bf27064397f19e4c3da4c Mon Sep 17 00:00:00 2001
From: Sebastian Rasmussen <sebras@gmail.com>
Date: Thu, 5 Aug 2021 11:48:10 +0200
Subject: [PATCH] jbig2dec: Do not redefine inline until all systemwide headers
 are included.

When cross-compiling jbig2dec like so:

./configure --host=i686-w64-mingw32 --disable-static && make clean && make

... you get linker errors about multiple definintions of llabs, lltoa, etc.

The reason for this is that the inline keyword has been redfined to the empty
string. After that has been done in jbig2.h it includes jbig2_priv.h which
includes memento.h which includes stdlib.h. The inline redefinition causes
all declarations in stdlib.h to then be done without inline causing the
functions to be present at least twice in in the set of object files.
The redefine was introduced in commit cb456c92a550e1af70a4e268b2f5b02f2df5b8c6

Since jbig2.h is jbig2dec's public header this would affect any program that
includes jbig2.h and then includes system-wide headers after that.

This commit circumvents the issue by moving the inline redefine from the end
of the public jbig2.h header to later in the internal jbig2_priv.h header,
immediately after memento.h has been included. This way the redefine still
affects any jbig2dec internal source code, but not any users of jbig2dec.
---
 jbig2.h      | 5 -----
 jbig2_priv.h | 5 +++++
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/jbig2.h b/jbig2.h
index c83517e..49fb1f0 100644
--- a/jbig2.h
+++ b/jbig2.h
@@ -105,11 +105,6 @@ void jbig2_release_page(Jbig2Ctx *ctx, Jbig2Image *image);
 /* mark the current page as complete, simulating an end-of-page segment (for broken streams) */
 int jbig2_complete_page(Jbig2Ctx *ctx);
 
-/* If we don't have a definition for inline, make it nothing so the code will compile */
-#ifndef inline
-#define inline
-#endif
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/jbig2_priv.h b/jbig2_priv.h
index ac341cd..ed366af 100644
--- a/jbig2_priv.h
+++ b/jbig2_priv.h
@@ -35,6 +35,11 @@
 
 /* library internals */
 
+/* If we don't have a definition for inline, make it nothing so the code will compile */
+#ifndef inline
+#define inline
+#endif
+
 typedef uint8_t byte;
 
 #define bool int
